package br.com.fatecpg.operon.frames;

import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;
import br.com.fatecpg.operon.Conexao;
import java.sql.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.text.DateFormatter;

/**
 *
 * @author Jonathan Santos RA: 1290371123111 - ADS FATECPG
 *
 */
public class CadastroProfessoresIFrame extends javax.swing.JInternalFrame {

    public CadastroProfessoresIFrame() {
        initComponents();
       
        try {
            atualizar();

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Erro: " + ex.getMessage(),
                    "Erro", JOptionPane.ERROR_MESSAGE);
            //this.dispose();
        }
        
        //tabela.setRowSelectionInterval(1, 1);
       // popularTextBox();
        
        
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        btn_novo = new javax.swing.JButton();
        btn_excluir = new javax.swing.JButton();
        btn_atualizar = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanelAlto = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();
        jPanelBaixo = new javax.swing.JPanel();
        lbl_cel = new javax.swing.JLabel();
        lbl_nome = new javax.swing.JLabel();
        lbl_id = new javax.swing.JLabel();
        lbl_end = new javax.swing.JLabel();
        lbl_come = new javax.swing.JLabel();
        lbl_cpf = new javax.swing.JLabel();
        lbl_apelido = new javax.swing.JLabel();
        lbl_data = new javax.swing.JLabel();
        lbl_email = new javax.swing.JLabel();
        lbl_res = new javax.swing.JLabel();
        txt_email = new javax.swing.JTextField();
        txt_apelido = new javax.swing.JTextField();
        txt_nome = new javax.swing.JTextField();
        txt_id = new javax.swing.JTextField();
        txf_telRes = new javax.swing.JFormattedTextField();
        txf_telCom = new javax.swing.JFormattedTextField();
        txf_telCel = new javax.swing.JFormattedTextField();
        txf_end = new javax.swing.JFormattedTextField();
        btn_gravar = new javax.swing.JButton();
        btn_cancelar = new javax.swing.JButton();
        txf_cpf = new javax.swing.JFormattedTextField();
        txf_dataNasc = new javax.swing.JFormattedTextField();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Cadastros de Professores");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jToolBar1.setRollover(true);

        btn_novo.setText("Novo");
        btn_novo.setFocusable(false);
        btn_novo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btn_novo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btn_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novoActionPerformed(evt);
            }
        });
        jToolBar1.add(btn_novo);

        btn_excluir.setText("Excluir");
        btn_excluir.setFocusable(false);
        btn_excluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btn_excluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btn_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_excluirActionPerformed(evt);
            }
        });
        jToolBar1.add(btn_excluir);

        btn_atualizar.setText("Atualizar");
        btn_atualizar.setFocusable(false);
        btn_atualizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btn_atualizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btn_atualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_atualizarActionPerformed(evt);
            }
        });
        jToolBar1.add(btn_atualizar);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.LINE_START);

        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Nome", "CPF", "Apelido", "Nascimento", "Email", "Tel. Residencial", "Tel. Comercial", "Celular", "Endereço"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tabela);

        javax.swing.GroupLayout jPanelAltoLayout = new javax.swing.GroupLayout(jPanelAlto);
        jPanelAlto.setLayout(jPanelAltoLayout);
        jPanelAltoLayout.setHorizontalGroup(
            jPanelAltoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1197, Short.MAX_VALUE)
        );
        jPanelAltoLayout.setVerticalGroup(
            jPanelAltoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAltoLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(jPanelAlto);

        lbl_cel.setText("CELULAR:");

        lbl_nome.setText("NOME:");

        lbl_id.setText("ID:");

        lbl_end.setText("ENDEREÇO:");

        lbl_come.setText("TELEFONE COMERCIAL:");

        lbl_cpf.setText("CPF:");

        lbl_apelido.setText("APELIDO:");

        lbl_data.setText("NASCIMENTO:");

        lbl_email.setText("E'MAIL:");

        lbl_res.setText("TELEFONE RESIDENCIAL:");

        try {
            txf_telRes.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-##-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            txf_telCom.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-##-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            txf_telCel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-##-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        btn_gravar.setText("Gravar");
        btn_gravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_gravarActionPerformed(evt);
            }
        });

        btn_cancelar.setText("Cancelar");
        btn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelarActionPerformed(evt);
            }
        });

        try {
            txf_cpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###.##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            txf_dataNasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##-##-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanelBaixoLayout = new javax.swing.GroupLayout(jPanelBaixo);
        jPanelBaixo.setLayout(jPanelBaixoLayout);
        jPanelBaixoLayout.setHorizontalGroup(
            jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBaixoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelBaixoLayout.createSequentialGroup()
                                .addComponent(lbl_end)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txf_end))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelBaixoLayout.createSequentialGroup()
                                .addComponent(lbl_id)
                                .addGap(2, 2, 2)
                                .addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lbl_nome)
                                .addGap(3, 3, 3)
                                .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbl_apelido)
                            .addComponent(lbl_cpf)))
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addComponent(lbl_res)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txf_telRes, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(54, 54, 54)
                        .addComponent(lbl_come)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addComponent(txt_apelido, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbl_email))
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addComponent(txf_telCom, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lbl_cel))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelBaixoLayout.createSequentialGroup()
                        .addComponent(txf_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbl_data)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txt_email, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txf_telCel, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txf_dataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(49, 49, 49)
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_cancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btn_gravar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanelBaixoLayout.setVerticalGroup(
            jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBaixoLayout.createSequentialGroup()
                .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_id)
                            .addComponent(lbl_nome)
                            .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelBaixoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_apelido)
                            .addComponent(txt_apelido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_email)
                            .addComponent(txt_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lbl_end)
                                .addComponent(txf_end, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lbl_cpf))
                        .addGap(11, 11, 11)
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_res)
                            .addComponent(txf_telRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_data)
                            .addComponent(txf_cpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txf_dataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelBaixoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txf_telCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_cel)
                            .addComponent(txf_telCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addComponent(btn_gravar)
                        .addGap(16, 16, 16)
                        .addComponent(lbl_come))
                    .addGroup(jPanelBaixoLayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(btn_cancelar)))
                .addGap(0, 292, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(jPanelBaixo);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.PAGE_END);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1213)/2, (screenSize.height-788)/2, 1213, 788);
    }// </editor-fold>//GEN-END:initComponents

    public void atualizar() throws SQLException {
        DefaultTableModel model = (DefaultTableModel) tabela.getModel();
        model.setRowCount(0);
        String sql = "SELECT * FROM operon.PROFESSORES";
        ResultSet rs = Conexao.con.createStatement().executeQuery(sql);
        while (rs.next()) {
            model.addRow(new Object[]{
                        rs.getInt("PROF_ID"),
                        rs.getString("NOME"),
                        rs.getString("CPF"),
                        rs.getString("APELIDO"),
                        rs.getString("NASCIMENTO"),
                        rs.getString("EMAIL"),
                        rs.getString("TEL_RES"),
                        rs.getString("TE_COM"),
                        rs.getString("CELULAR"),
                        rs.getString("ENDERECO")
                    });
        }
    }
    

    private void btn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelarActionPerformed
    
        limparTextBox();
        desativarTextBox();
        desativarGravarCancelar();
      //  jPanelBaixo.setVisible(false);
        
    }//GEN-LAST:event_btn_cancelarActionPerformed

    private void btn_gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_gravarActionPerformed
        ativarTextBox();
        
        int id = Integer.parseInt(txt_id.getText());
        String nome = txt_nome.getText();
        String cpf = txf_cpf.getText();
        String apelido = txt_apelido.getText();
        String nasc = txf_dataNasc.getText(); 
        String email = txt_email.getText();
        String tel_res = txf_telRes.getText();
        String tel_com = txf_telCom.getText();
        String celular = txf_telCel.getText();
        String endereco = txf_end.getText();

        String SQL = "INSERT INTO operon.PROFESSORES VALUES(" + id + ",'" + nome + "','" + cpf + "','" + apelido + "','" + nasc + "','" + email + "','" + tel_res + "','" + tel_com + "','" + celular + "','" + endereco + "')";
        
        try {
            Conexao.con.createStatement().execute(SQL);
            //this.dispose();

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "0 registro não pode ser inserido. Erro: " + ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
        }
        
        //Atualizando
        try {
            atualizar();

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Erro: " + ex.getMessage(),
                    "Erro", JOptionPane.ERROR_MESSAGE);
            //this.dispose();
        }
       
       desativarTextBox();
       limparTextBox();    
    }//GEN-LAST:event_btn_gravarActionPerformed


    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
     desativarGravarCancelar();  
     desativarTextBox();
     //jPanelBaixo.setVisible(false);
    }//GEN-LAST:event_formInternalFrameOpened

    
    private void btn_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novoActionPerformed
    // jPanelBaixo.setVisible(true); 
     ativarTextBox();
     ativarGravarCancelar();         
       
    }//GEN-LAST:event_btn_novoActionPerformed
  
    
     public void desativarGravarCancelar (){
       btn_cancelar.setEnabled(false);
       btn_gravar.setEnabled(false);
    }
     
     public void ativarGravarCancelar (){
       btn_cancelar.setEnabled(true);
       btn_gravar.setEnabled(true);
    }
    
     
     public void limparTextBox (){
       txt_id.setText(" ");
        txt_nome.setText(" ");
        txf_cpf.setText(" ");
        txt_apelido.setText(" ");
        txf_dataNasc.setText(" ");
        txt_email.setText(" ");
        txf_telRes.setText(" ");
        txf_telCom.setText(" ");
        txf_telCel.setText(" ");
        txf_end.setText(" ");

    }
      
     
    public void desativarTextBox (){
       txt_id.setEditable(false);
        txt_nome.setEditable(false);
        txf_cpf.setEditable(false);
        txt_apelido.setEditable(false);
        txf_dataNasc.setEditable(false);
        txt_email.setEditable(false);
        txf_telRes.setEditable(false);
        txf_telCom.setEditable(false);
        txf_telCel.setEditable(false);
        txf_end.setEditable(false);

    }
  
  
    public void ativarTextBox (){
      txt_id.setEditable(true);
        txt_nome.setEditable(true);
        txf_cpf.setEditable(true);
        txt_apelido.setEditable(true);
        txf_dataNasc.setEditable(true);
        txt_email.setEditable(true);
        txf_telRes.setEditable(true);
        txf_telCom.setEditable(true);
        txf_telCel.setEditable(true);
        txf_end.setEditable(true);
    }
    
    
    public void popularTextBox (){
    if(tabela.getSelectedRow() >= 0){ 
          String id = tabela.getValueAt(tabela.getSelectedRow(),0).toString(); 
          String nome = tabela.getValueAt(tabela.getSelectedRow(),1).toString(); 
          String cpf = tabela.getValueAt(tabela.getSelectedRow(),2).toString(); 
          String apelido = tabela.getValueAt(tabela.getSelectedRow(),3).toString();
          String nasc = tabela.getValueAt(tabela.getSelectedRow(),4).toString();
          String email = tabela.getValueAt(tabela.getSelectedRow(),5).toString(); 
          String tel_res = tabela.getValueAt(tabela.getSelectedRow(),6).toString();
          String tel_com = tabela.getValueAt(tabela.getSelectedRow(),7).toString(); 
          String celular = tabela.getValueAt(tabela.getSelectedRow(),8).toString();
          String endereco = tabela.getValueAt(tabela.getSelectedRow(),9).toString();
         
          popularControles(id, nome, cpf, apelido, nasc, email, tel_res,
          tel_com, celular, endereco);
         
          }else{ JOptionPane.showMessageDialog(this, "Nenhum RegistroSelecionado");}
    }
    
    
    public void popularControles(String id, String nome, String cpf, String apelido, String nasc, String email, String tel_res, String tel_com, String celular, String endereco) {

        txt_id.setText(id);
        txt_nome.setText(nome);
        txf_cpf.setText(cpf);
        txt_apelido.setText(apelido);
        txf_dataNasc.setText(nasc);
        txt_email.setText(email);
        txf_telRes.setText(tel_res);
        txf_telCom.setText(tel_com);
        txf_telCel.setText(celular);
        txf_end.setText(endereco);

    }
    
    
    private void btn_atualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_atualizarActionPerformed
          try {
            atualizar();

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Erro: " + ex.getMessage(),
                    "Erro", JOptionPane.ERROR_MESSAGE);
            //this.dispose();
        }
    }//GEN-LAST:event_btn_atualizarActionPerformed

    private void btn_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_excluirActionPerformed
        if (tabela.getSelectedRow()>=0){
            String código = tabela.getValueAt(tabela.getSelectedRow(),0).toString();
        if(JOptionPane.showConfirmDialog(this, "Confirma exclusão do registro"+código)==JOptionPane.YES_OPTION){
            String SQL="DELETE FROM operon.PROFESSORES WHERE PROF_ID="+código;
        try{
            Conexao.con.createStatement().execute(SQL);
            this.atualizar();
        }catch (SQLException ex){
            JOptionPane.showMessageDialog(this, "0 registro não pode ser excluido. Erro: "+ex.getMessage(),"Erro",JOptionPane.ERROR_MESSAGE);
        }}
        }
    }//GEN-LAST:event_btn_excluirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_atualizar;
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JButton btn_excluir;
    private javax.swing.JButton btn_gravar;
    private javax.swing.JButton btn_novo;
    private javax.swing.JPanel jPanelAlto;
    private javax.swing.JPanel jPanelBaixo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lbl_apelido;
    private javax.swing.JLabel lbl_cel;
    private javax.swing.JLabel lbl_come;
    private javax.swing.JLabel lbl_cpf;
    private javax.swing.JLabel lbl_data;
    private javax.swing.JLabel lbl_email;
    private javax.swing.JLabel lbl_end;
    private javax.swing.JLabel lbl_id;
    private javax.swing.JLabel lbl_nome;
    private javax.swing.JLabel lbl_res;
    private javax.swing.JTable tabela;
    private javax.swing.JFormattedTextField txf_cpf;
    private javax.swing.JFormattedTextField txf_dataNasc;
    private javax.swing.JFormattedTextField txf_end;
    private javax.swing.JFormattedTextField txf_telCel;
    private javax.swing.JFormattedTextField txf_telCom;
    private javax.swing.JFormattedTextField txf_telRes;
    private javax.swing.JTextField txt_apelido;
    private javax.swing.JTextField txt_email;
    private javax.swing.JTextField txt_id;
    private javax.swing.JTextField txt_nome;
    // End of variables declaration//GEN-END:variables
}
